package com.yunji.app.order;

import com.yunji.common.annotation.Log;
import com.yunji.common.base.BaseController;
import com.yunji.common.base.response.Response;
import com.yunji.common.base.response.ResponseHelper;
import com.yunji.common.enums.common.BusinessType;
import com.yunji.common.model.dto.LoginInfo;
import com.yunji.common.utils.ExcelUtil;
import com.yunji.common.utils.bean.BeanUtils;
import com.yunji.order.business.PayoutBusiness;
import com.yunji.order.domain.PayoutDO;
import com.yunji.order.dto.PayoutPageDTO;
import com.yunji.order.dto.PayoutCreateDTO;
import com.yunji.system.context.SystemContext;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * @Package com.yunji.app.order
 * FileName:	GetWayPayoutController.java
 * Copyright:	Copyright © 2024 云集互联 All Rights Reserved
 * Company:		云集互联
 * @version: 1.0
 * @since: JDK 1.8.0_202
 * Create at:   2024-04-22 09:32:24
 * Description:
 * 移动端-用户提现
 * Modification History:
 * Author					Date						Version			Description
 * --------------------------------------------------------------------------------
 * HuaAo				2024-04-22 09:32:24			1.0				1.0 Version
 */
@RestController
@Api(tags = "移动端-用户提现")
@RequestMapping("/gateway/payout/")
public class AppPayoutController extends BaseController {
    @Resource
    private PayoutBusiness payoutBusiness;


    @ApiOperation("提现申请")
    @PostMapping(value = "/addPayout")
    public Response<Long> create(@Valid @RequestBody PayoutCreateDTO payout) {
        LoginInfo user = SystemContext.getUser();
        Assert.isTrue(BeanUtils.isNotNull(user), "请先登录后再操作");
        payoutBusiness.createPayout(payout);
        return ResponseHelper.success();
    }

    @ApiOperation("查询提现列表")
    @GetMapping("/list")
    public Response<List<PayoutDO>> list(PayoutPageDTO payout) {
        List<PayoutDO> list = payoutBusiness.searchPayout(payout);
        return ResponseHelper.successWithPage(list);
    }

    @ApiOperation("导出提现信息")
    @Log(title = "提现", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(PayoutPageDTO payout) {
        payout.setExport(true);
        List<PayoutDO> list = payoutBusiness.searchPayout(payout);
        ExcelUtil<PayoutDO> util = new ExcelUtil<>(PayoutDO.class);
        util.exportExcel(response, list, "提现数据");
    }

    @ApiOperation("获取提现详细信息")
    @GetMapping(value = "/{id}")
    public Response<PayoutDO> getInfo(@PathVariable("id") Long id) {
        return ResponseHelper.success(payoutBusiness.selectPayout(id));
    }

    @ApiOperation("关闭提现申请")
    @PostMapping(value = "/closed")
    public Response<String> closed(Long id) {
        payoutBusiness.closedPayout(id);
        return ResponseHelper.success();
    }
}
